/**
 * youtube视频详情播放页面
 * @author tanggf
*/
$(function(){
	youtube_detail.run();
});

var youtube_detail = {	
		run: function(){
			this.__init__();
			this._start_();
			this._bind_events();
		},
		
		__init__: function(){
			this.contextPath = $("#contextPath").val() || "";
			this.showId = $("#showId").val();
			this.type = $("#type").val();		
			this.genres = encodeURIComponent($("#genres").val());
			this.category = $("#category").val();
			this.itemUrl = $("#itemUrl").val();
			this.title = $("#title").val();
			this.source = $("#source").val();
			this.vdInstalled = vd.check();
		},
		_start_: function(){
			share.run();
			
			var path = location.pathname;
			if(path.indexOf("/world/featured/") >= 0){
				this.isI18n = true;
				$("#side_menu > ul > li").eq(0).addClass("curr");
			}
		},
		
		_get_recent_releases: function(){	
			var url = this.contextPath + "/video/movie/other/"+this.category+"/"+this.genres+"?id="+this.showId;				
			$.get(url, function(result){
				$("#new_release_div").html(result.trim());

			});
		},

		_bind_events: function(){
			//this._get_recent_releases();
			
			//play now btn
			$("#play_btn").click(function(){
				var title = youtube_detail.title;
				_gaq.push(['_trackEvent', 'movie', 'Play', title]);
				//main.addOrUpdateViewHistory('movie', title, youtube_detail.showId);
				var url = youtube_detail.contextPath + "/more/" + youtube_detail.category + "/play/" + youtube_detail.showId;
				location.href = url;
			});			
			
			$("#fb-comments").attr("data-href", location.href);		
		}		
};

var share = {
		run: function(){
			//share btn
			$("#share_btn").click(function(){
				$("#share_fb_div").slideToggle();
				$("#share_fb_div > span.share-close").click(function(){
					$("#share_fb_div").slideUp();
				});
			});
			
			var url = location.href;
			$("#share_input").val(url);
			
			$("#fb_share_a").click(function(){
				var fbUrl = "https://www.facebook.com/sharer.php?u=" + encodeURIComponent(url);
				_gaq.push(['_trackEvent', 'Movie', 'fb_share', url]);	
				window.open(fbUrl);
			});
			
			$("#tw_share_a").click(function(){
				var twUrl = "https://twitter.com/share?url=" +encodeURIComponent(url);
				_gaq.push(['_trackEvent', 'Movie', 'twitter_share', url]);				
				window.open(twUrl);
			});
		}
};
